import request from '@/utils/http'

//分类

// 新增
export const addCategoryAPI = (data) => {
  return request({
    url: 'admin/category',
    method: 'POST',
    data
  });
};

// 查询
export const getCategoryAPI = () => {
  return request({
    url: 'admin/category',
    method: 'GET'
  });
};

// 删除
export const deleCategoryAPI = (id) => {
  return request({
    url: 'admin/category',
    method: 'DELETE',
    params: {
      id
    }
  });
};

// 修改
export const editCategoryAPI = (data) => {
  return request({
    url: 'admin/category',
    method: 'PUT',
    data
  });
};

// 根据id查询分类和商品信息
export function  getCategoryDetailAPI (id) {
  return request({
    url: '/category',
    method: 'GET',
    params: {
      id
    }
  })
}

//子分类

// 新增
export const addSubCategoryAPI = (data) => {
  return request({
    url: 'admin/subcategory',
    method: 'POST',
    data
  });
};

// 分页查询
export const getSubCategoryPageAPI = (params) => {
  return request({
    url: 'admin/subcategory/page',
    method: 'GET',
    params
  });
};

// 删除
export const deleSubCategoryAPI = (ids) => {
  return request({
    url: 'admin/subcategory',
    method: 'DELETE',
    params: {
      ids
    }
  });
};

// 修改
export const editSubCategoryAPI = (data) => {
  return request({
    url: 'admin/subcategory',
    method: 'PUT',
    data
  });
};

//查询
export const getSubCategoryAPI = () => {
  return request({
    url: 'admin/subcategory',
    method: 'GET'
  });
};

//面包屑
export const getBreadcrumbAPI = (id) => {
  return request({
    url: '/category/sub/breadcrumb',
    method: 'GET',
    params: {
      id
    }
  })
}

//根据子分类id获取商品信息
export const getGoodsAPI = (data) => {
  return request({
    url: '/category/sub/goods',
    method: 'POST',
    data
  })
}